package com.smsc.headend.task.engine.handler.impl.collection.strategy;

import com.smsc.headend.module.data.enums.CollectionSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.stereotype.Component;

@Component
public class CollectionStrategyFactory {
    @Autowired
    AutowireCapableBeanFactory autowireCapableBeanFactory;


    public CollectionStrategy getCollectionStrategy(CollectionSource collectionSource) {
        CollectionStrategy collectionStrategy;
        switch (collectionSource) {
            case ARR:
                collectionStrategy = new AutoRecollectionStrategy();
                break;
            case MARR:
                collectionStrategy = new ManualRecollectionStrategy();
                break;
            case SCH:
                collectionStrategy = new ScheduleCollectionStrategy();
                break;
            case ODR:
                collectionStrategy = new ManualOnDemandReadStrategy();
                break;
            case FTP:
            default:
                collectionStrategy = null;
        }
        if (collectionStrategy != null) {
            autowireCapableBeanFactory.autowireBean(collectionStrategy);
            return collectionStrategy;
        }
        return null;
    }
}
